package com.office.automate.dto.convertors;

import javax.servlet.http.HttpServletRequest;

import com.office.automate.frontier.utility.DataConversionUtility;
import com.office.automate.model.employee.Employee;
import com.office.automate.model.employee.EmployeeOverTime;
import com.office.automate.model.employee.EmployeeQualification;
import com.office.automate.model.employee.EmployeeSearch;

public class EmployeeDetailsConvertor {

	private DataConversionUtility dcUtility = new DataConversionUtility();

	public Employee convertRegisterEmployeeRequest(HttpServletRequest request) {
		Employee employee = new Employee();
		employee.setUsername(request.getParameter("username"));
		employee.setPassword(request.getParameter("password"));
		employee.setConfirmPassword(request.getParameter("confirmPassword"));
		employee.setSecurityLevel(dcUtility.convertToNumber(request.getParameter("securityLevel")));
		employee.setFirstName(request.getParameter("firstName"));
		employee.setMiddleName(request.getParameter("middleName"));
		employee.setLastName(request.getParameter("lastName"));
		employee.setNic(request.getParameter("nic"));
		employee.setEmail(request.getParameter("email"));
		employee.setNationality(request.getParameter("nationality"));
		employee.setAddressLine1(request.getParameter("addressLine1"));
		employee.setAddressLine2(request.getParameter("addressLine2"));
		employee.setCity(request.getParameter("city"));
		employee.setZipCode(dcUtility.convertToNumber(request.getParameter("zipCode")));
		employee.setSalary(dcUtility.convertToDouble(request.getParameter("salary")));
		employee.setDateOfBirth(dcUtility.convertToDate(request.getParameter("birthyear") + "-" + request.getParameter("birthmonth") + "-" + request.getParameter("birthday")));
		employee.setGender(request.getParameter("sex"));
		employee.setCivilStatus(request.getParameter("civilstatus"));
		employee.setDesignationCode(dcUtility.convertToNumber(request.getParameter("designation")));
		employee.setBranchId(dcUtility.convertToLong(request.getParameter("branch")));
		employee.setDivisionId(dcUtility.convertToLong(request.getParameter("division")));
		employee.setManagerId(dcUtility.convertToLong(request.getParameter("managerorsupervisor")));
		employee.setCompanyJoinedDate(dcUtility.convertToDate(request.getParameter("joinedyear") + "-" + request.getParameter("joinedmonth") + "-" + request.getParameter("joinedday")));
		employee.setEmployeeDescription(request.getParameter("employeedescription"));
		employee.setPaymentType(request.getParameter("paymentType"));
		employee.setBankName(request.getParameter("bankName"));
		employee.setAccountNumber(dcUtility.convertToNumber(request.getParameter("accountNo")));
		employee.setContactNo(dcUtility.convertToNumber(request.getParameter("contactNo")));

		return employee;
	}

	public EmployeeQualification convertEmployeeQualificationRequest(HttpServletRequest request) {
		EmployeeQualification employeeQualification =new EmployeeQualification();
		employeeQualification.setEmployeeId(dcUtility.convertToLong(request.getParameter("employeeid")));
		employeeQualification.setDescription(request.getParameter("description"));
		employeeQualification.setType(request.getParameter("qualificationtype"));
		employeeQualification.setStartDate(dcUtility.convertToDate(request.getParameter("startyear") + "-" + request.getParameter("startmonth") + "-" + request.getParameter("startdate")));
		employeeQualification.setEndDate(dcUtility.convertToDate(request.getParameter("endyear") + "-" + request.getParameter("endmonth") + "-" + request.getParameter("enddate")));
		return employeeQualification;
	}

	public EmployeeQualification convertQualificationDataGridRequest(HttpServletRequest request) {
		EmployeeQualification employeeQualification = new EmployeeQualification();
		employeeQualification.setEmployeeId(dcUtility.convertStringToNumber(request.getParameter("Field0")));
		employeeQualification.setType(request.getParameter("Field1"));
		employeeQualification.setDescription(request.getParameter("Field2"));
		employeeQualification.setDataRowId(dcUtility.convertToLong(request.getParameter("Field5")));
		return employeeQualification;
	}

	public EmployeeSearch convertEmployeeSearchRequest(HttpServletRequest request) {
		EmployeeSearch employeeSearch =new EmployeeSearch();
		employeeSearch.setEmployeeId(dcUtility.convertToLong(request.getParameter("employeeId")));
		employeeSearch.setFirstName(request.getParameter("firstName"));
		employeeSearch.setMiddleName(request.getParameter("middleName"));
		employeeSearch.setLastName(request.getParameter("lastName"));
		employeeSearch.setNic(request.getParameter("niceNumber"));
		employeeSearch.setEmail(request.getParameter("emailAddress"));
		return employeeSearch;
	}

	public Employee convertEmployeeGridRequest(HttpServletRequest request) {
		Employee employee = new Employee();
		employee.setEmployeeId(dcUtility.convertStringToNumber(request.getParameter("Field1")));
		employee.setFirstName(request.getParameter("Field2"));
		employee.setLastName(request.getParameter("Field3"));
		employee.setContactNo(dcUtility.convertStringToNumber(request.getParameter("Field4")));
		return employee;
	}

	public Employee convertUpdateEmployeeRequest(HttpServletRequest request) {
		Employee employee = new Employee();
		employee.setEmployeeId(dcUtility.convertToLong(request.getParameter("employeeId")));
		employee.setUsername(request.getParameter("username"));
		employee.setPassword(request.getParameter("password"));
		employee.setConfirmPassword(request.getParameter("confirmPassword"));
		employee.setSecurityLevel(dcUtility.convertToNumber(request.getParameter("securityLevel")));
		employee.setFirstName(request.getParameter("firstName"));
		employee.setMiddleName(request.getParameter("middleName"));
		employee.setLastName(request.getParameter("lastName"));
		employee.setNic(request.getParameter("nic"));
		employee.setEmail(request.getParameter("email"));
		employee.setNationality(request.getParameter("nationality"));
		employee.setAddressLine1(request.getParameter("addressLine1"));
		employee.setAddressLine2(request.getParameter("addressLine2"));
		employee.setCity(request.getParameter("city"));
		employee.setZipCode(dcUtility.convertToNumber(request.getParameter("zipCode")));
		employee.setSalary(dcUtility.convertToDouble(request.getParameter("salary")));
		employee.setDateOfBirth(dcUtility.convertToDate(request.getParameter("birthyear") + "-" + request.getParameter("birthmonth") + "-" + request.getParameter("birthday")));
		employee.setGender(request.getParameter("sex"));
		employee.setCivilStatus(request.getParameter("civilstatus"));
		employee.setDesignationCode(dcUtility.convertToNumber(request.getParameter("designation")));
		employee.setBranchId(dcUtility.convertToLong(request.getParameter("branch")));
		employee.setDivisionId(dcUtility.convertToLong(request.getParameter("division")));
		employee.setManagerId(dcUtility.convertToLong(request.getParameter("managerorsupervisor")));
		employee.setCompanyJoinedDate(dcUtility.convertToDate(request.getParameter("joinedyear") + "-" + request.getParameter("joinedmonth") + "-" + request.getParameter("joinedday")));
		employee.setEmployeeDescription(request.getParameter("employeedescription"));
		employee.setPaymentType(request.getParameter("paymentType"));
		employee.setBankName(request.getParameter("bankName"));
		employee.setAccountNumber(dcUtility.convertToNumber(request.getParameter("accountNo")));
		employee.setContactNo(dcUtility.convertToNumber(request.getParameter("contactNo")));

		return employee;
	}

	public EmployeeOverTime convertEmployeeOTRequest(HttpServletRequest request) {
		EmployeeOverTime employeeOverTime = new EmployeeOverTime();
		employeeOverTime.setNumberOfHours(dcUtility.convertToDouble(request.getParameter("numberOfHours")));
		employeeOverTime.setOvertimeDate(dcUtility.convertToDate(request.getParameter("overtimeyear") + "-" + request.getParameter("overtimemonth") + "-" + request.getParameter("overtimeday")));
		employeeOverTime.setReasonForOverTime(request.getParameter("reason"));

		return employeeOverTime;
	}
}